<template>
  <div class="autumn-container">
    <!-- 面包 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/dashboard' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>消息记录</el-breadcrumb-item>
    </el-breadcrumb>

    <div class="autumn-center">
      <!-- 搜索栏 -->
      <div class="query-form">
        <autumn-search :modelValue="queryInfo" @search="search">
          <template #default>
            <el-col :span="4">
              <el-form-item prop="contact" label="联系人">
                <el-input v-model="queryInfo.contact" />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item prop="type" label="类型">
                <el-select v-model="queryInfo.type" placeholder="请选择">
                  <el-option v-for="(value, key, index) in $listDict('MESSAGE_TYPE')" :key="index" :label="value"
                    :value="key"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </template>
        </autumn-search>
      </div>

      <!-- 数据表格 -->
      <div class="main-body top">
        <autumn-table :page="page" @changePage="search">
          <template #column>
            <el-table-column type="index" label="#" fixed="left" align="center">
              <template #default="scope">
                {{ initIndex(scope.$index) }}
              </template>
            </el-table-column>
            <el-table-column prop="type" label="类型" width="100" align="center">
              <template #default="scope">
                {{ $getDictLabel('MESSAGE_TYPE', scope.row.type, '其它') }}
              </template>
            </el-table-column>
            <el-table-column prop="contact" label="联系人" show-overflow-tooltip />
            <el-table-column prop="content" label="消息内容" show-overflow-tooltip />
            <el-table-column prop="createName" label="发送人" width="100" />
            <el-table-column prop="createTime" label="发送时间" width="150" align="center"
              :formatter="(row: any) => $moment(row.createTime, 'YYYY-MM-DD HH:mm')" />
            <el-table-column label="状态" width="100" align="center">
              <template #default="scope">
                <el-tag type="success" size="small" v-if="scope.row.status == '1'">成功</el-tag>
                <el-tag type="danger" size="small" v-else>失败</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="remark" label="备注" />
          </template>
        </autumn-table>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import hooks from 'src/hook/index'
import { $moment, $listDict, $getDictLabel } from 'src/util/tools'
import { pageMessageLog } from 'src/api/message/messageLog'

//分页查询
const queryInfo = reactive({
  contact: '',
  type: ''
})
const { page, initIndex, search } = hooks.useTable((pageNumber: number, pageSize: number) => {
  pageMessageLog({ ...queryInfo, pageNumber, pageSize }).then(({ data }) => {
    page.data = data.list
    page.total = data.total
  })
})

</script>

<style lang="scss" scoped></style>
